package me.keiwu.admin.controller;

import me.keiwu.admin.service.GalleryService;
import me.keiwu.pub.data.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by kei on 07/12/2017.
 */
@RestController
@RequestMapping("/api/gallery")
public class GalleryController {


    @Autowired
    private GalleryService galleryService;



    @RequestMapping("/list")
    public Response list(@RequestParam(defaultValue = "0") Integer page,
                         @RequestParam(defaultValue = "10") Integer size) {
        return Response.ok(galleryService.list(page, size));
    }


    @RequestMapping("/upload")
    public Response upload(MultipartFile file, String desc) {
        return Response.ok(galleryService.upload(file, desc));
    }

    @RequestMapping("/delete")
    public Response delete(Long id) {
        galleryService.delete(id);
        return Response.ok();
    }

}
